package com.yaozheng.vocationaltraining.view;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.adapter.QuestionNumberListAdapter;
import com.yaozheng.vocationaltraining.dialog.BaseDialog;
import com.yaozheng.vocationaltraining.dialog.interfaces.BaseDialogEventProcess;
import com.yaozheng.vocationaltraining.iview.IQuestionNumberView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 试题号列表
 *
 * @author Administrator
 */
@EViewGroup(R.layout.view_dialog_question_number_list)
public class QuestionNumberListView extends LinearLayout {
    @ViewById
    GridView questionNumberList;
    @ViewById
    TextView questionAnsweredText, questionNoAnswerText;


    BaseDialogEventProcess baseDialog;

    QuestionNumberListAdapter questionNumberListAdapter;

    public BaseDialogEventProcess getBaseDialog() {
        return baseDialog;
    }

    public void setBaseDialog(BaseDialogEventProcess baseDialog) {
        this.baseDialog = baseDialog;
    }


    public QuestionNumberListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    public QuestionNumberListView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }

    @AfterViews
    public void initView() {

    }

    /**
     * 隐藏
     */
    @Click({R.id.questionListMenuLayout, R.id.exmaSelectQuestionCloseImage})
    public void questionListMenuClick() {
        if (baseDialog != null) {
            baseDialog.runMethod("cancel");
        }
    }

    /**
     * 刷新数据
     *
     * @param iQuestionNumberView
     */
    public void refreshData(IQuestionNumberView iQuestionNumberView,
                            int answeredCount) {
        if (iQuestionNumberView != null) {
            int count = iQuestionNumberView.getCount();
            questionAnsweredText.setText("已答" + answeredCount);
            questionNoAnswerText.setText("未答" + (count - answeredCount));

            if (questionNumberListAdapter == null) {
                questionNumberListAdapter = new QuestionNumberListAdapter(
                        getContext(), iQuestionNumberView);
                questionNumberList.setAdapter(questionNumberListAdapter);
            } else {
                questionNumberListAdapter.notifyDataSetChanged();
            }
        }
    }

}
